//
//  LrcTableViewCell.m
//  kyMusicPlayer
//
//  Created by 翁科宇 on 2018/5/17.
//  Copyright © 2018年 翁科宇. All rights reserved.
//

#import "LrcTableViewCell.h"

@implementation LrcTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

+ (LrcTableViewCell *)KY_CellForRowWithTableView:(UITableView *)tableView{
    NSString *cellID = @"lrcCellID";
    LrcTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[LrcTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.backgroundColor = [UIColor clearColor];
    }
    return cell;
}

- (void)addAnimation:(AnimationType)animationType{
    switch (animationType) {
        case translation:{
            [self.layer removeAnimationForKey:@"translation"];
            CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.x"];
            animation.values = [NSArray arrayWithObjects:@50,@0,@50,@0, nil];
            animation.duration = 0.7;
            animation.repeatCount = 1;
            [self.layer addAnimation:animation forKey:@"translation"];
            break;
        }
        case scale:{
            [self.layer removeAnimationForKey:@"scale"];
            CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.x"];
            animation.values = [NSArray arrayWithObjects:@0.5, @1.0, nil];
            animation.duration = 0.7;
            animation.repeatCount = 1;
            animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
            [self.layer addAnimation:animation forKey:@"scale"];
            break;
        }
        case rotation:{
            [self.layer removeAnimationForKey:@"rotation"];
            CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
            animation.values = [NSArray arrayWithObjects:[NSNumber numberWithDouble:(-1/6*M_PI)],[NSNumber numberWithDouble:0],[NSNumber numberWithDouble:(1/6*M_PI)],[NSNumber numberWithDouble:0], nil];
            animation.duration = 0.7;
            animation.repeatCount = 1;
            [self.layer addAnimation:animation forKey:@"rotation"];
            break;
        }
        case scaleAlways:{
            CABasicAnimation *animation1 = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
            animation1.repeatCount = 1;
            animation1.duration = 0.6;
            animation1.autoreverses = YES;// 动画结束时执行逆动画
            // 缩放倍数
            animation1.fromValue = [NSNumber numberWithFloat:1.0];// 开始时的倍率
            animation1.toValue = [NSNumber numberWithFloat:1.2];// 结束时的倍率
            [self.layer addAnimation:animation1 forKey:@"scale-layer"];
            break;
        }
        case scaleNormal:{
            break;
        }
        default:
            break;
    }
}

@end
